#include "stdafx.h"
#include "TreeIntersection.h"
#include <iostream>
#include <list>
#include <boost/system/config.hpp>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/AABB_triangle_primitive.h>

typedef K SimpleK;

typedef SimpleK::FT FT;
typedef SimpleK::Ray_3 Ray;
typedef SimpleK::Line_3 Line;
typedef SimpleK::Point_3 Point;
typedef SimpleK::Triangle_3 Triangle;

//typedef std::list<Triangle>::iterator Iterator;
//typedef CGAL::AABB_triangle_primitive<SimpleK, Iterator> Primitive;
//typedef CGAL::AABB_traits<SimpleK, Primitive> AABB_triangle_traits;
//typedef CGAL::AABB_tree<AABB_triangle_traits> Tree;
//typedef boost::optional< Tree::Intersection_and_primitive_id<Triangle>::Type > Triangle_intersection;
//
//void Test()
//{
//	Point a(1.0, 0.0, 0.0);
//	Point b(0.0, 1.0, 0.0);
//	Point c(0.0, 0.0, 1.0);
//	Point d(0.0, 0.0, 0.0);
//
//	std::list<Triangle> triangles;
//	triangles.push_back(Triangle(a, b, c));
//	triangles.push_back(Triangle(a, b, d));
//	triangles.push_back(Triangle(a, d, c));
//
//	// constructs AABB tree
//	Tree tree(triangles.begin(), triangles.end());
//
//	// counts #intersections
//	Ray ray_query(a, b);
//	std::cout << tree.number_of_intersected_primitives(ray_query)
//		<< " intersections(s) with ray query" << std::endl;
//
//	// compute closest point and squared distance
//	Point point_query(2.0, 2.0, 2.0);
//	Point closest_point = tree.closest_point(point_query);
//	std::cerr << "closest point is: " << closest_point << std::endl;
//	FT sqd = tree.squared_distance(point_query);
//	std::cout << "squared distance: " << sqd << std::endl;
//
//	//Triangle tri(b, c, d);
//	//std::list<Triangle_intersection> intersections;
//	//tree.all_intersections(tri, std::back_inserter(intersections));
//
//	ZMTreeIntersection<SimpleK, Tree, Tree> Int(&tree, &tree);
////	Int.Intersection();
//}